package com.ashin;

import com.ashin.bean.User;
import com.ashin.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MybatisSpringDemo {

    public static void main(String[] args) {
        mybatisSpringDemo();
    }

    private static void mybatisSpringDemo() {
        ApplicationContext ac = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml"});
        // 从Spring容器中根据bean的id取出我们要使用的userService对象
        UserService userService = (UserService) ac.getBean("userService");

        User user = new User();

        user.setAge(12);
        user.setName("zjh");
        user.setAddress("test");
        userService.addUser(user);
        System.out.println(user);
        System.out.println(userService.getUserById(user.getId()));
    }
}
